package com.example.page;


import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import java.util.List;

public class FilmsPage extends InternalPage{

    @FindBy(xpath = "//*[@id=\"results\"]/a")
    public List<WebElement> linksToFilms;

    public boolean isFilmFound(String film_name)
    {
        for (int i = 0; i< linksToFilms.size(); i++)
        {
            if (linksToFilms.get(i).findElement(By.cssSelector("div[class = \"title\"]")).getText().equals(film_name))
                return true;
        }
        return false;
    }

    public boolean isclickOnFilm(String film_name)
    {
        if (isFilmFound(film_name))
        {
            for (int i = 0; i< linksToFilms.size(); i++)
            {
                if (linksToFilms.get(i).findElement(By.cssSelector("div[class = \"title\"]")).getText().equals(film_name))
                {
                    linksToFilms.get(i).click();
                    return true;
                }
            }
        }
        return false;
    }

    public boolean isFilmSelected(String film_name) {
        return isclickOnFilm(film_name);
    }
}
